SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO


CREATE PROC [dbo].[SP_TXMVTO_BANC_I01]      
/*--------------------------------------------------------------*/     
/*------ Empresa          : OFISIS S.A.                    -----*/    
/*------ Cliente   : OFISIS S.A.                    -----*/    
/*------ Sistema    : Contabilidad                   -----*/    
/*------ Modulo           : Empresa                        -----*/    
/*------ Programa         : Transferencia Doc. Cuentas Banc-----*/    
/*------ Script           : TXEXTR_BANC                    -----*/    
/*------ Nombre      : SP_TXMVTO_BANC_I01             -----*/     
/*------ Desarrollado por : Luz Gonzalez                   -----*/      
/*------ Fecha            : 17/10/2002                     -----*/    
/*------ Base de Datos    : MS SQL Server                  -----*/    
/*------ Version          : 7                              -----*/    
/*------ Invoca a SP      :                                -----*/    
/*--------------------------------------------------------------*/    
/*--------------------------------------------------------------*/    
/*------ Comentarios      :                                -----*/    
/*--------------------------------------------------------------*/    
/*--------------------------------------------------------------*/    
/*------ MODIFICADO POR   : PERCY GARCIA                   -----*/    
/*------ FECHA MODIF.     : 07/04/2004                     -----*/    
/*------ DETALLE MODIF.   : TIPO DATO CUENTA 20, VALIDA LA -----*/    
/*------ OPERACION DE DIF. DE CAMBIO DOCS. PENDIENTES, se coloco is null en where -----*/    
/*--------------------------------------------------------------*/     
/*--------------------------------------------------------------*/     
/*------ Drop proc SP_TXMVTO_BANC_I01                      -----*/            
/*------ Grant all on SP_TXMVTO_BANC_I01 To PUBLIC         -----*/     
/*------ SP_TXMVTO_BANC_I01 '01', 1, 1999, 2, '42101'      -----*/     
/*--------------------------------------------------------------*/     
@ISCO_EMPR         TD_VC_002,     
@ISCO_USUA          TD_VC_008,  
@IDFE_USUA          TD_DT_001,  
@INNU_CNTB_EMPR    TD_IN_001,    
@INNU_ANNO         TD_IN_004_ANNO,     
@INNU_MESE         TD_IN_002_MESE,    
@ISCO_CNTA_EMPR    TD_VC_020     
As     
Declare      
@VSCO_OPRC_DIFE    TD_VC_003,    
@VSCO_OPRC    TD_VC_003,    
@CDFE_DOCU         TD_DT_001,      
@CSTI_DOCU         TD_VC_003,      
@CSNU_DOCU         TD_VC_020,      
@CSCO_MONE         TD_VC_003,      
@CNIM_MVTO_DOCU    TD_NU_016_004,      
@CSTI_OPER         TD_VC_003,      
@VNNU_CONT         TD_IN_001,    
@VSID_0004         TD_VC_003,     
@VSCO_OPRC_PEND    TD_VC_003      
    
Select @VSCO_OPRC = ID_DIFE, @VSID_0004 = ID_0004    
From TTCNTB_EMPR    
Where CO_EMPR = @ISCO_EMPR    
  and NU_CNTB_EMPR = @INNU_CNTB_EMPR    
    
Select @VSCO_OPRC_DIFE = CO_OPRC_CNTB    
 from TTIDEN_OPER    
 where CO_EMPR = @ISCO_EMPR    
   and NU_CNTB_EMPR = @INNU_CNTB_EMPR    
   and ID_OPRC = @VSCO_OPRC    
    
 Select @VSCO_OPRC_PEND = CO_OPRC_CNTB    
 From TTIDEN_OPER    
 Where CO_EMPR = @ISCO_EMPR    
 And NU_CNTB_EMPR = @INNU_CNTB_EMPR    
 And ID_OPRC = @VSID_0004    
    
Declare CU_TXMVTO_BANC_I01_1 Cursor    
for    
  Select MAX(FE_DOCU), TI_DOCU, NU_DOCU, CO_MONE, Isnull(sum(Isnull(IM_MVTO_ORIG, 0)), 0),     
  TI_OPER       
  from TXMVTO_CNTB    
  where CO_EMPR = @ISCO_EMPR     
  and   NU_CNTB_EMPR = @INNU_CNTB_EMPR     
  And   CO_OPRC_CNTB != IsNull(@VSCO_OPRC_DIFE, '')     
  And   CO_OPRC_CNTB != IsNull(@VSCO_OPRC_PEND, '')    
  and   NU_ANNO = @INNU_ANNO     
  and   NU_MESE = @INNU_MESE     
  and   CO_CNTA_EMPR = @ISCO_CNTA_EMPR     
  and   IsNull(Rtrim(TI_DOCU), '') != ''    
  and   IsNull(Rtrim(NU_DOCU), '') != ''    
  and   SI_MVTO_CNTB = 'APR'    
group by TI_DOCU, NU_DOCU, CO_MONE, TI_OPER     
    
Select @VNNU_CONT = 0    
    
/*--- Borro lo que estaba antes en la tabla de extracto ---*/    
Delete TXMVTO_BANC      
 Where CO_EMPR = @ISCO_EMPR    
   and NU_CNTB_EMPR = @INNU_CNTB_EMPR    
   and NU_ANNO = @INNU_ANNO    
   and NU_MESE = @INNU_MESE    
   and CO_CNTA_EMPR = @ISCO_CNTA_EMPR     
    
open CU_TXMVTO_BANC_I01_1     
fetch CU_TXMVTO_BANC_I01_1 into @CDFE_DOCU, @CSTI_DOCU, @CSNU_DOCU, @CSCO_MONE,     
 @CNIM_MVTO_DOCU, @CSTI_OPER     
    
While @@Fetch_Status = 0      
Begin       
  Select @VNNU_CONT = @VNNU_CONT + 1     
  insert into TXMVTO_BANC(CO_EMPR, NU_CNTB_EMPR, NU_ANNO, NU_MESE, CO_CNTA_EMPR,            
                        NU_SECU, TI_DOCU, NU_DOCU, FE_DOCU, CO_MONE, IM_MVTO_DOCU,     
                        ST_FLAG, TI_OPER, CO_USUA_CREA, FE_USUA_CREA,     
   CO_USUA_MODI, FE_USUA_MODI, NU_ANNO_CONS,NU_MESE_CONS)       
   values(@ISCO_EMPR, @INNU_CNTB_EMPR, @INNU_ANNO, @INNU_MESE, @ISCO_CNTA_EMPR,            
          @VNNU_CONT, @CSTI_DOCU, @CSNU_DOCU, @CDFE_DOCU, @CSCO_MONE, @CNIM_MVTO_DOCU,     
          'N', @CSTI_OPER, @ISCO_USUA , @IDFE_USUA, @ISCO_USUA, @IDFE_USUA, NULL,NULL)     
    
fetch CU_TXMVTO_BANC_I01_1 into @CDFE_DOCU, @CSTI_DOCU, @CSNU_DOCU, @CSCO_MONE,     
 @CNIM_MVTO_DOCU, @CSTI_OPER      
End     
close CU_TXMVTO_BANC_I01_1     
deallocate CU_TXMVTO_BANC_I01_1     
return     
/*------------------------------------- Fin -----------------------------------*/  
  





GO
